package com.fahai.utils;

/**
 * Created by sky on 17/3/1.
 * 连接jdbc连接的工具类
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JdbcUtil {
    public static final String url = "jdbc:mysql://admin.xproj.net:9527/hotline_online?useUnicode=true&autoReconnect=true&rewriteBatchedStatements=TRUE";
    public static final String name = "com.mysql.jdbc.Driver";
    public static final String user = "dba_dev";
    public static final String password = "Fahaijiayou_123";

    public static Connection conn = null;
    public static PreparedStatement pst = null;

    static {
        try{
            Class.forName(name);//指定连接类型
            conn = DriverManager.getConnection(url, user, password);//获取连接
        }catch (Exception e) {

        }
    }
    public JdbcUtil(String sql) {
        try {
            pst = conn.prepareStatement(sql);//准备执行语句
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //    static 类型则不用关闭jdbc连接,初始化只连一个
    public void close() {
        try {
            this.conn.close();
            this.pst.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}




